<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Geolocation Components Demo - zoom effect</title>
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
        <style>
            * {margin: 0; padding: 0; border: 0;}
            body {
                position: absolute;
                width: 100%;
                height: 100%;
            }
            #geoPage, #markPage {
                position: relative;
            }
        </style>
        <title>地理位置获取</title>
    </head>
<body>
<!--  通过 iframe 嵌入前端定位组件，此处没有隐藏定位组件，使用了定位组件的在定位中视觉特效  -->
<iframe id="geoPage" width="100%" height="30%" frameborder=0 scrolling="no"
        src="https://apis.map.qq.com/tools/geolocation?key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77&referer=myapp&effect=zoom"></iframe>

<script type="text/JavaScript">
	var loc;
	//var isMapInit = false;
	//监听定位组件的message事件
	window.addEventListener('message', function(event) {
		loc = event.data; // 接收位置信息
		console.log('location', loc);//console显示信息
		
	}, false);
	//为防止定位组件在message事件监听前已经触发定位成功事件，在此处显示请求一次位置信息
	document.getElementById("geoPage").contentWindow.postMessage('getLocation',
			'*');

	//设置6s超时，防止定位组件长时间获取位置信息未响应
	setTimeout(function() {
		if (!loc) {
			//主动与前端定位组件通信（可选），获取粗糙的IP定位结果
			document.getElementById("geoPage").contentWindow.postMessage(
					'getLocation.robust', '*');
		}
	}, 6000); //6s为推荐值，业务调用方可根据自己的需求设置改时间，不建议太短
</script>

</body> 
</html>